var basePath="";
var countnum=9;
var actionid="";
var rentorderid="";
$(document).ready(function(){
	knowS();
	CheckOrder();
});

//每隔1秒请求一次订单状态
function knowS(){
	actionid=window.setInterval("wantS()",1000);
	layer.close(LoadingIcon);
}
//请求订单状态
function wantS(){
//	var orderid=$("div.weixinpay_orderid").text();
//	var orderid="fbfe4ba9faa74888a2dea9097605ae35"//模拟数据
	rentorderid = $("div.weixinpay_orderid").text();
	$.ajax({	
		dataType : "json",
		type : "post",
		url : basePath+"/car/orderstate",
		data : {
			orderid:rentorderid
		},
		
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(data) {
			if(data.data.state=="success"){
				console.log("停止");
				$("div#myModal").modal("show");
//				启动计数器
				window.setInterval("count()",1000);
				window.clearInterval(actionid);
				
			};		
		},
		error : function() {
			console.log("访问失败");
		},
		complete : function() {
			
		},
	});
}
//计数器
function count(){
	$("text#countnum").text(countnum);
	countnum--;
	console.log("countnum="+countnum);
	if(countnum==-1){
		window.close();		
	}
	
}
//点击查看订单详情
var CheckOrder = function(){
	$("button.btn-primary").click(function(){
		var url = basePath+"/linerepay";
		window.location.href = (url);
	});
}
